﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class BuidlEditor : Editor
{
	[MenuItem("Build/SwitchToRelease")]
	private static void SwitchToRelease()
	{
		#if UNITY_ANDROID
		PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
		
		string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android);
		defines = defines.Replace("UNITY_DEBUG", "UNITY_RELEASE");
		PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, defines);

		PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, Il2CppCompilerConfiguration.Release);

		#elif UNITY_IOS
		string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS);
		defines = defines.Replace("UNITY_DEBUG", "UNITY_RELEASE");
		PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, defines);

		#elif UNITY_STANDALONE
		PlayerSettings.SetScriptingBackend(BuildTargetGroup.Standalone, ScriptingImplementation.IL2CPP);

		string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
		defines = defines.Replace("UNITY_DEBUG", "UNITY_RELEASE");
		PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, defines);

		PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Standalone, Il2CppCompilerConfiguration.Release);

		#endif

		Debug.Log("SwitchToRelease, Success! Platform:" + Application.platform.ToString());
	}

	[MenuItem("Build/SwtichToDeubg")]
	private static void SwitchToDebug()
	{
		#if UNITY_ANDROID
		PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.Mono2x);

		string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android);
		defines = defines.Replace("UNITY_RELEASE", "UNITY_DEBUG");
		PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, defines);
		
		#elif UNITY_IOS
		string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS);
		defines = defines.Replace("UNITY_RELEASE", "UNITY_DEBUG");
		PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, defines);

		#elif UNITY_STANDALONE
		PlayerSettings.SetScriptingBackend(BuildTargetGroup.Standalone, ScriptingImplementation.Mono2x);

		string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
		defines = defines.Replace("UNITY_RELEASE", "UNITY_DEBUG");
		PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, defines);

		#endif

		Debug.Log("SwitchToDebug, Success! Platform:" + Application.platform.ToString());
	}
}
